package com.mall.admin.controller;

import com.mall.admin.service.SmsFlashPromotionService;
import com.mall.commons.utils.PageResult;
import com.mall.commons.utils.R;
import com.mall.domain.SmsFlashPromotion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/flash")
public class SmsFlashPromotionController {

    @Autowired
    private SmsFlashPromotionService smsFlashPromotionService;

    //添加活动
    @PostMapping("/create")
    public R create(@RequestBody SmsFlashPromotion smsFlashPromotion){
        smsFlashPromotionService.create(smsFlashPromotion);
        return R.success("添加活动",null);
    }

    //删除活动
    @PostMapping("/delete/{id}")
    public R delete(@PathVariable Long id){
        smsFlashPromotionService.delete(id);
        return R.success("删除活动",null);
    }

    //根据活动名称分页查询
    @GetMapping("/list")
    public R list(String keyword,Integer pageNum,Integer pageSize){
        PageResult pageResult = smsFlashPromotionService.list(keyword,pageNum,pageSize);
        return R.success("分页查询",pageResult);
    }

    //修改上下线状态
    @PostMapping("/update/status/{id}")
    public R updateStatus(@PathVariable Long id,Integer status){
        smsFlashPromotionService.updateStatus(id,status);
        return R.success("修改上下线状态",1);
    }

    //编辑活动
    @PostMapping("/update/{id}")
    public R update(@PathVariable Long id,@RequestBody SmsFlashPromotion smsFlashPromotion){
        smsFlashPromotionService.update(id,smsFlashPromotion);
        return R.success("编辑活动",1);
    }

    //获取活动详情
    @GetMapping("/{id}")
    public R find(@PathVariable Long id){
        SmsFlashPromotion smsFlashPromotion = smsFlashPromotionService.findById(id);
        return R.success("获取活动详情",smsFlashPromotion);
    }
}
